import actions from './actions'
import getters from './getters'
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  actions,
  getters,
  state: {
    // 记录当前用户
    currentUser: {},
    // 记录用户是否登录
    isLogin: false,
    // 用户按钮权限
    userPermission: [],
    // 用户的token
    userToken: '',
    // 保存theaterManage中theaterpath数据
    currentTheaterPath: '',
    // 保存最新评论数据
    newcomment: [],
    // 保存本月演出数据
    monthshowdata: []
  },
  mutations: {
    // 保存用户登录信息
    userStatus (state, user) {
      if (user) {
        this.state.currentUser = user.username
        this.state.userPermission = user.userPermission
        this.state.userToken = user.token
        this.state.isLogin = true
      } else if (user === {}) {
        window.sessionStorage.set('token', '')
        this.state.currentUser = {}
        this.state.isLogin = false
      }
    },
    // 清除用户登录信息
    clearUserStatus (state) {
      this.state.currentUser = null
      this.state.userPermission = []
      this.state.userToken = ''
      this.state.isLogin = false
    },
    // 保存theaterpath
    savepath (state, path) {
      this.state.currentTheaterPath = path
    },
    // 保存newcomment
    savenewcomment (state, data) {
      this.state.newcomment = data
    },
    // 保存monthshowdata
    savemonthshowdata (state, data) {
      this.state.monthshowdata = data
    }
  }
})
